package com.hison.tandainbao.controller;

import com.hison.tandainbao.entiy.pojo.dto.AddJob;
import com.hison.tandainbao.entiy.pojo.dto.JobInfo;
import com.hison.tandainbao.response.ResponseResult;
import com.hison.tandainbao.service.TbJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: JobController
 * @Descripiton: 招聘控制类
 * @Author: 小郑
 * @Date： 2024/3/30 9:19
 * @Version：1.8
 **/
@RequestMapping("/job")
@RestController
@Api(value = "职位信息管理接口", tags = "职位信息管理接口")
public class JobController {

    @Autowired
    private TbJobService jobService;



    //------------------------------ 用户端 ----------------------------------

    /**
     * 获取全部职位信息
     *
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/30
     * @see ResponseResult
     * @since version
     *///1.浏览所有的招聘信息   包括返回对对应的类别
    @GetMapping("/getAll")
    @ApiOperation(value = "获取所有发布的审核通过的招聘信息",produces = "application/json",httpMethod = "GET")
    public ResponseResult getAll(){
        return jobService.getAll();
    }

    //2.搜索职位
    @GetMapping("/getJob/{jobName}")
    @ApiOperation(value = "根据职位名称模糊查询相关的职位信息",produces = "application/json",httpMethod = "GET")
    public  ResponseResult getJobByName(@PathVariable("jobName") String jobName){
        return  jobService.getJobByName(jobName);
    }

    /**
     * 按作业 ID 获取作业
     *
     * @param jobId 作业 ID
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/30
     * @see String
     * @see ResponseResult
     * @since version
     *///3.查看职位的详细情况
    @GetMapping("/getJobByJobId/{jobId}")
    @ApiOperation(value = "查看职位详细信息",produces = "application/json",httpMethod = "GET")
    public ResponseResult getJobByJobId(@PathVariable("jobId") String jobId){
        return jobService.getJobByJobId(jobId);
    }


    /**
     * 更新作业状态
     *
     * @param status 地位
     * @param jobId  作业 ID
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/30
     * @see String
     * @see String
     * @see ResponseResult
     * @since version
     *///4.设置职位状态 正在招募，停止招募
    @PutMapping("/updateJobStatus")
    @ApiOperation(value = "更新职位状态",produces = "application/json",httpMethod = "PUT")
    public  ResponseResult updateJobStatus(@RequestParam("status") String status,@RequestParam("jobId") String jobId){
        return jobService.updateJobStatus(status,jobId);
    }

    /**
     * 添加作业
     *
     * @param job 工作
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/30
     * @see AddJob
     * @see ResponseResult
     * @since version
     *///发布职位
    @PostMapping("/add")
    @ApiOperation(value = "发布招聘职位",produces = "application/json",httpMethod = "POST")
    public  ResponseResult  addJob(@RequestBody AddJob job){
        return  jobService.addJob(job);
    }


    /**
     * 更新作业
     *
     * @param jobInfo 职位信息
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/30
     * @see JobInfo
     * @see ResponseResult
     * @since version
     *///编辑职位信息
    @PutMapping("/updateJob")
    @ApiOperation(value = "修改发布的职位信息",produces = "application/json",httpMethod = "PUT")
    public ResponseResult  updateJob(@RequestBody JobInfo jobInfo){
        return  jobService.updateJob(jobInfo);
    }


    //TODO 浏览自己发布的招聘信息
    @GetMapping("/getMyJobInfo")
    @ApiOperation(value = "查找自己发布的信息")
    public  ResponseResult getMyJobInfoAll(){
        return  jobService.getMyJobInfoAll();
    }




    /**
     * 删除作业
     *
     * @param jobId 作业 ID
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/30
     * @see String
     * @see ResponseResult
     * @since version
     *///删除职位
    @DeleteMapping("/delete/{jobId}")
    @ApiOperation(value = "根据id删除职位信息",produces = "application/json",httpMethod = "DELETE")
    public  ResponseResult  deleteJob(@PathVariable("jobId") String jobId){
        return jobService.deleteJob(jobId);
    }
    //-----------------  管理员端  -------------

    //1.查看所有
    @GetMapping("/getAllByAdmin")
    @ApiOperation(value = "管理员获取所有的职位信息",produces = "application/json",httpMethod = "GET")
    public  ResponseResult getAllByAdmin(@RequestParam(value = "current", defaultValue = "1") int current, @RequestParam(value = "total",defaultValue = "10") int total){
        return  jobService.getAllByAdmin(current, total);
    }

    //2.删除
    @DeleteMapping("/deleteByAdmin/{jobId}")
    @ApiOperation(value = "根据id删除职位信息",produces = "application/json",httpMethod = "DELETE")
    public  ResponseResult  deleteJobByAdmin(@PathVariable("jobId") String jobId){
        return jobService.deleteJob(jobId);
    }

    //3.审核
    @PutMapping("/updateJobStatusByAdmin")
    @ApiOperation(value = "管理员审核",produces = "application/json",httpMethod = "PUT")
    public ResponseResult updateJobStatusByAdmin(@RequestParam("jobId") String jobId,@RequestParam("status") String status){
        return  jobService.updateJobStatusByAdmin(jobId,status);
    }
}